public class Solution {
    public static void main(String[] args) {
        int[] nums = {1,2,3,1};
        System.out.println(rob(nums));
    }
    //爬楼梯
    public int climbStairs(int n) {
        if(n < 3) {
            return n;
        }
        int[] dp = new int[n+1];
        dp[0] = 0;
        dp[1] = 1;
        dp[2] = 2;
        for(int i = 3; i <= n; i++) {
            dp[i] = dp[i-1] + dp[i-2];
        }
        return dp[n];
    }
    

    //打家劫舍
    public static int rob(int[] nums) {
        int n = nums.length;
        //f[i]表示i位置偷此时的最大值
        //g[i]表示i位置时不偷的最大值
        int[] f = new int[n];
        int[] g = new int[n];
        f[0] = nums[0];
        for(int i = 1; i < n; i++) {
            f[i] = Math.max(f[i-1] ,g[i-1] + nums[i]);
            g[i] = Math.max(f[i-1], g[i-1]);
        }
        return Math.max(g[n-1],f[n-1]);
    }
}
